Skip to content

fix: preserve ProjectionExec metadata during serialization - #25009

Open
goutamadwant wants to merge 2 commits into
apache:mainfrom
goutamadwant:fix-projection-proto-metadata-24695
Open

fix: preserve ProjectionExec metadata during serialization#25009
goutamadwant wants to merge 2 commits into
apache:mainfrom
goutamadwant:fix-projection-proto-metadata-24695

Conversation

@goutamadwant

@goutamadwant goutamadwant commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Physical-plan serialization can lose projection field and schema metadata. The projection's payload should preserve that metadata without relying on the child to reconstruct it.

What changes are included in this PR?

  • Add an optional schema to ProjectionExecNode, emitted when the projection has schema or output-field metadata, or explicitly clears input metadata.
  • Restore metadata through try_new_with_schema_metadata, keeping field names, data types, and nullability derived from the expressions.
  • Preserve decoding of older payloads without the optional field.

What is the testing strategy for this PR?

  • The new child-independent regression fails before the encoding change and passes afterward.
  • Independent binary and JSON round trips cover inherited and overridden metadata, schema-only and field-only metadata, extension metadata, explicit clearing, metadata-free projections, and older payloads.
  • Decoding tests verify expression-derived field properties and reject metadata schemas with too few or too many fields.
  • The projection-focused tests pass, and repeating protobuf generation produces no further changes.
  • Full-workspace all-target, all-feature Clippy passes after merging current main, which includes the upstream PostgreSQL formatter lint fix.
  • The required extended workspace suite passes, including 2,279 physical-plan tests, 272 protobuf integration tests, and all 518 SQL logic-test files.
  • The contributor guide's ./dev/rust_lint.sh checks pass, including the private-item documentation build.

Are there any user-facing changes?

Projection schema and output-field metadata survive physical-plan serialization. Nested field definitions remain part of the expression-derived data types. The generated ProjectionExecNode Rust struct gains an optional schema field, which affects exhaustive struct literals. New readers continue to accept older payloads. This targets main, not a 55.1 backport.

@github-actions github-actions Bot added proto Related to proto crate physical-plan Changes to the physical-plan crate labels Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Thank you for opening this pull request!

Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).

Details
     Cloning apache/main
    Building datafusion-physical-plan v55.1.0 (current)
       Built [  42.656s] (current)
     Parsing datafusion-physical-plan v55.1.0 (current)
      Parsed [   0.165s] (current)
    Building datafusion-physical-plan v55.1.0 (baseline)
       Built [  37.479s] (baseline)
     Parsing datafusion-physical-plan v55.1.0 (baseline)
      Parsed [   0.166s] (baseline)
    Checking datafusion-physical-plan v55.1.0 -> v55.1.0 (no change; assume patch)
     Checked [   1.078s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [  83.414s] datafusion-physical-plan
    Building datafusion-proto v55.1.0 (current)
       Built [  53.621s] (current)
     Parsing datafusion-proto v55.1.0 (current)
      Parsed [   0.026s] (current)
    Building datafusion-proto v55.1.0 (baseline)
       Built [  53.667s] (baseline)
     Parsing datafusion-proto v55.1.0 (baseline)
      Parsed [   0.020s] (baseline)
    Checking datafusion-proto v55.1.0 -> v55.1.0 (no change; assume patch)
     Checked [   0.157s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [ 109.030s] datafusion-proto
    Building datafusion-proto-models v55.1.0 (current)
       Built [  24.567s] (current)
     Parsing datafusion-proto-models v55.1.0 (current)
      Parsed [   0.139s] (current)
    Building datafusion-proto-models v55.1.0 (baseline)
       Built [  24.424s] (baseline)
     Parsing datafusion-proto-models v55.1.0 (baseline)
      Parsed [   0.140s] (baseline)
    Checking datafusion-proto-models v55.1.0 -> v55.1.0 (no change; assume patch)
     Checked [   2.598s] 223 checks: 222 pass, 1 fail, 0 warn, 31 skip

--- failure constructible_struct_adds_field: struct exhaustively constructible through public API adds field ---

Description:
A pub struct that could be exhaustively constructed with a literal using only public API has a new pub field, breaking existing exhaustive literals.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field ProjectionExecNode.schema in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:2238
  field ProjectionExecNode.schema in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:2238

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [  53.203s] datafusion-proto-models

@github-actions github-actions Bot added the auto detected api change Auto detected API change label Sep 7, 2026
@codecov-commenter

codecov-commenter commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.95%. Comparing base (c2cf289) to head (0b93056).

Files with missing lines Patch % Lines
datafusion/physical-plan/src/projection.rs 85.00% 0 Missing and 3 partials ⚠️
datafusion/proto-models/src/generated/pbjson.rs 76.92% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25009      +/-   ##
==========================================
+ Coverage   81.90%   81.95%   +0.04%     
==========================================
  Files        1134     1134              
  Lines      425261   425293      +32     
  Branches   425261   425293      +32     
==========================================
+ Hits       348325   348559     +234     
+ Misses      56295    56049     -246     
- Partials    20641    20685      +44     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jayzhan211 jayzhan211 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @goutamadwant !

@gene-bordegaray gene-bordegaray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One concern, other than that thank you 👍

let input = ctx.encode_child(input)?;
let expr = ctx.encode_expressions(projection_exprs.iter().map(|p| &p.expr))?;
let expr_name = projection_exprs.iter().map(|p| p.alias.clone()).collect();
let schema = if *overrides_metadata {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditioins shouldnt just be if we are overriding metadata I believe. Rather we should be checking if we have metadata in general.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gene-bordegaray Updated the condition to encode schema or output-field metadata even when inherited. The override check remains so an empty metadata map can still explicitly clear input metadata.

));
let plan = Arc::new(ProjectionExec::try_new(
vec![(col("value", &input_schema)?, "value".to_string())],
Arc::new(EmptyExec::new(Arc::clone(&input_schema))),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is preserving the metadata through the child after decoding, not a proojection that needs to rederive the metadata completely from itself.

Could we add a test that forces the projection to completely rederive the metadata from its own proto after roundtrip 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gene-bordegaray added a regression that removes metadata from the encoded child and checks the decoded projection independently. Let me know if it looks good now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto detected api change Auto detected API change physical-plan Changes to the physical-plan crate proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Physical-plan serialization drops ProjectionExec metadata

4 participants